#include "Qt3DPicker.h"

#include "HideFaceHandler.h"
#include "CmdManager.h"
#include "Scene.h"
#include "SelectHandler3D.h"
#include "OSGNodeMask.h"

HideFaceHandler::HideFaceHandler()
{
}
HideFaceHandler::~HideFaceHandler()
{
}

void HideFaceHandler::input(const QVariant & data, const QString & rawInput, CommandSource cs)
{
	auto scene = getScene();
	auto sph = getSendPointHandler();
	auto selector = qobject_cast<SelectHandler3D*>(getSelectHandler());
	if (data.type() == QVariant::Bool)
	{
		bool esc = !data.toBool();
		if (esc)
		{
			selector->clearSelection();
			clearInput();
			emit finished();
			return;
		}
	}

	if (status() == 0)
	{
		if (selector)
		{
			selector->clearSelection();
			selector->beginSelect(D3SurfaceMask);
			prompt(1, tr("选择要隐藏的面: "));
		}
		else
		{
			emit finished();
		}
		return;
	}

	if (status() == 1)
	{
		if (selector && selector->done())
		{
			auto selections = selector->selectionSet();
			if (selections.size() > 0)
			{
				for (auto selection : selections)
				{
					std::shared_ptr<Ent> ent = std::dynamic_pointer_cast<Ent>(selection);
					ent->getRep3D()->setNodeMask(0);
				}
				selector->clearSelection();
			}
		}
		emit finished();
		return;
	}
}
